package com.googlecode.bip.entity.impl;

import java.io.Serializable;
import java.sql.ResultSet;
import java.sql.SQLException;
import com.googlecode.bip.entity.IUserReferent;

/**
 * Association between 1 {@link IUser} and 1 or more {@link IReferent}
 *
 * @author Claude CHOISNET
 */
public class UserReferent
    implements IUserReferent, Serializable
{
    private static final long serialVersionUID = 1L;

    private int iduser; //key
    private int idreferent; //key

    /**
     *
     */
    public UserReferent()
    {
    }

    /**
     * Create a shadow copy of giving UserReferent
     *
     * @param o UserReferent to clone
     */
    public UserReferent( final UserReferent o )
    {
        this.iduser     = o.iduser;
        this.idreferent = o.idreferent;
    }

    /**
     *
     * @param rSet
     * @return
     * @throws SQLException
     */
    public IUserReferent set( final ResultSet rSet ) throws SQLException
    {
        // from uservalues
        iduser      = rSet.getInt( "iduser" );
        idreferent  = rSet.getInt( "idreferent" );

        return this;
    }

    @Override
    public int getIdUser()
    {
        return this.iduser;
    }

    @Override
    public void setIdUser( int iduser )
    {
        this.iduser = iduser;
    }

    @Override
    public int getIdReferent()
    {
        return this.idreferent;
    }

    @Override
    public void setIdReferent( int idreferent )
    {
        this.idreferent = idreferent;
    }

    /* (non-Javadoc)
     * @see java.lang.Object#hashCode()
     */
    @Override
    public int hashCode()
    {
        final int prime = 31;
        int result = 1;
        result = prime * result + idreferent;
        result = prime * result + iduser;
        return result;
    }

    /* (non-Javadoc)
     * @see java.lang.Object#equals(java.lang.Object)
     */
    @Override
    public boolean equals( Object obj )
    {
        if( this == obj ) {
            return true;
        }
        if( obj == null ) {
            return false;
        }
        if( getClass() != obj.getClass() ) {
            return false;
        }
        UserReferent other = (UserReferent)obj;
        if( idreferent != other.idreferent ) {
            return false;
        }
        if( iduser != other.iduser ) {
            return false;
        }
        return true;
    }

    /* (non-Javadoc)
     * @see java.lang.Object#toString()
     */
    @Override
    public String toString()
    {
        return "UserReferent [iduser=" + iduser
                + ", idreferent=" + idreferent
                + "]";
    }

}
